#
# AS - C++ Application server
#
PROJECT(cas)

CMAKE_MINIMUM_REQUIRED(VERSION 2.4.2 FATAL_ERROR)

# ################################################################################
# Macroses
#

# Standard CMake macroses
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckLibraryExists)

# User-defined macroses
INCLUDE(cmake/ConfigureLibrary.cmake)
INCLUDE(cmake/ConfigurePackage.cmake)
INCLUDE(cmake/RenameModule.cmake)

# ################################################################################
# Set system-specific data
#
MESSAGE(STATUS "#### System name is: ${CMAKE_SYSTEM_NAME}")

# ################################################################################
# Setup libraries & headers
#

#
# Configure CTPP2 package
#
CONFIGURE_PACKAGE(ctpp2-config ctpp2 CTPP2)

#
# Configure CAS package
#
CONFIGURE_PACKAGE(cas-config cas CAS)

#
# SQLayer library
#
CONFIGURE_LIBRARY(SQLayer.hpp "/usr/include/sqlayer /usr/local/include/sqlayer /opt/include/sqlayer"
                  sqlayer     "/lib /usr/lib /usr/local/lib /opt/lib")

INCLUDE_DIRECTORIES(include)

# ################################################################################
# Lib binary
#
    SET(CMAKE_CXX_FLAGS " -g ")

ADD_LIBRARY(cassqlconnector SHARED src/ASSQLConnectorObject.cpp)
TARGET_LINK_LIBRARIES(cassqlconnector ${HAVE_ctpp2} ${HAVE_cas} ${HAVE_sqlayer})

ADD_LIBRARY(mod_sql_module MODULE src/ASSQLConnector.cpp)
TARGET_LINK_LIBRARIES(mod_sql_module cassqlconnector)
RENAME_MODULE(mod_sql_module mod_sql_module)

# ################################################################################
# Install library headers
#
INSTALL(FILES include/ASSQLConnectorObject.hpp
        DESTINATION include/cas/modules
        PERMISSIONS OWNER_READ OWNER_WRITE
                    GROUP_READ
                    WORLD_READ)

# ################################################################################
# Install library
#
INSTALL(TARGETS cassqlconnector DESTINATION lib)

# ################################################################################
# Install modules
#
INSTALL(FILES mod_sql_module.so
        DESTINATION libexec/cas
        PERMISSIONS OWNER_READ OWNER_WRITE
                    GROUP_READ
                    WORLD_READ)

# End.
